﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CardLogistics.Web.Components;
using System.Data;

namespace CardLogistics.Web.MainPage.Ordering.Ordering_Cardinfo
{
    public partial class OrderCardExportRpt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string orderId = Request.QueryString["orderId"];//订单ID
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" SELECT * FROM V_OrderCardExport WHERE 1=1 ");
            if (orderId.Trim().Length > 0)
            {
                sbStr.Append(" and Id='" + orderId + "'");
            }
            //OracleXMLReportData.GenDetailData(this, sbStr.ToString());

            DataSet myds = new DataSet();
            DataTable dt = DAL.DbHelperSQL.GetQueryResult(sbStr.ToString());
            //设置金额大小写
            if (dt != null && dt.Rows.Count > 0)
            {
                string strformatname = "";//版面类型
                int cardTotal = 0;//总数量
                string type = "";//印刷方式
                string SpareParts = "";//备品信息
                string bigTotal = "";//总数量大写
                string bigSpareParts = "";//备品信息大写数量
                string atturl = "";//版面图片
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strformatname += dt.Rows[i]["formatname"].ToString() + dt.Rows[i]["formatnumber"].ToString() + "张\r\n";
                    cardTotal += int.Parse(dt.Rows[i]["formatnumber"].ToString());
                    bool flag = type.Contains(dt.Rows[i]["FORMATMODE"].ToString());//判断是否重复
                    if (!flag)
                    {
                        type += dt.Rows[i]["FORMATMODE"].ToString() + "+";
                    }
                    atturl += dt.Rows[i]["formatname"].ToString() + "|" + dt.Rows[i]["atturl"].ToString() + ",";
                }
                SpareParts += "(包含";
                bigSpareParts += "(包含";
                if (dt.Rows[0]["SPAREPARTS"].ToString() != "" && dt.Rows[0]["SPAREPARTS"].ToString() != "0")
                {
                    SpareParts += dt.Rows[0]["SPAREPARTS"].ToString() + "张备品";
                    //金额转为大写金额
                    bigSpareParts += BasePage.MoneyToChinese(dt.Rows[0]["SPAREPARTS"].ToString()) + "备品";
                }
                if (dt.Rows[0]["PREMIUMS"].ToString() != "" && dt.Rows[0]["PREMIUMS"].ToString() != "0")
                {
                    SpareParts += dt.Rows[0]["PREMIUMS"].ToString() + "张赠品";
                    //金额转为大写金额
                    bigSpareParts += BasePage.MoneyToChinese(dt.Rows[0]["PREMIUMS"].ToString()) + "赠品";
                }
                SpareParts += ")";
                bigSpareParts += ")";
                dt.Rows[0]["formatname"] = strformatname;//修改版面类型值
                //创建table的备品信息列
                DataColumn SparePartsColumn = new DataColumn();
                SparePartsColumn.DataType = System.Type.GetType("System.String");//该列的数据类型 
                SparePartsColumn.ColumnName = "SpareParts";//该列得名称 备品信息
                // 将列添加到table上 
                dt.Columns.Add(SparePartsColumn);
                dt.Rows[0]["SpareParts"] = SpareParts;//修改备品信息

                //创建table的张数大写列 
                DataColumn bigTotalColumn = new DataColumn();
                bigTotalColumn.DataType = System.Type.GetType("System.String");//该列的数据类型 
                bigTotalColumn.ColumnName = "bigTotal";//该列得名称 张数大写
                // 将列添加到table上 
                dt.Columns.Add(bigTotalColumn);
                //金额转为大写金额
                bigTotal = BasePage.MoneyToChinese(cardTotal.ToString());
                dt.Rows[0]["bigTotal"] = bigTotal;//修改备品信息

                //创建table的备品数量大写列 
                DataColumn bigSparePartsColumn = new DataColumn();
                bigSparePartsColumn.DataType = System.Type.GetType("System.String");//该列的数据类型 
                bigSparePartsColumn.ColumnName = "bigSpareParts";//该列得名称 备品数量大写
                // 将列添加到table上 
                dt.Columns.Add(bigSparePartsColumn);
                dt.Rows[0]["bigSpareParts"] = bigSpareParts;//修改备品数量大写

                dt.Rows[0]["formatnumber"] = cardTotal;//修改总数量
                dt.Rows[0]["FORMATMODE"] = type.TrimEnd('+');//修改印刷方式
                dt.Rows[dt.Rows.Count - 1]["ATTURL"] = atturl.TrimEnd(',');//版面图片
            }
            myds.Tables.Add(dt);
            XMLReportData.GenDetailData(this, myds, ResponseDataType.ZipBinary);
        }
    }
}